﻿using System.Collections.Generic;
using System.Windows.Media;

namespace MyFloridaHouse.libSvUtilities.CustomColors
{
    public class PreDefinedColors : ICustomColors
    {
        //NOTE: This was the list, some combinations are invalid
        private static string colorDefinitions =
         "FFFFFF,88fdb0,feba83,c3fcfe,fefd0d,c8a8cc,4dc68c,fe9e9e,9cbfbf,c8a846,"
       + "f2abf7,a3cb91,faae1b,9bc8ff,e7e359,03e0ff,c9f97b,fc7886,d6d6d6,dd9002,"
       + "968ed6,40e446,e4a2ab,82ffd2,fff5a9,e9e2fc,dbeaa5,57cad8,e0fdec,bda977,"
       + "1ccbd3,FF99CC,FF3399,CCFF66,CC9933,CC3300,99CCFF,9966CC,990099,66CC66,"
       + "666633,3399FF,3333CC,00FF99,009966,FFFFCC,FF9999,FF3366,CCFF33,CC9900,"
       + "CC00FF,99CCCC,996699,990066,66CC33,666600,33FFFF,3399CC,333399,00FF66,"
       + "009933,FFFF99,FF9966,FF3333,CCFF00,CC66FF,CC00CC,99CC99,996666,990033,"
       + "66CC00,6633FF,33FFCC,339999,00FF33,009900,FFFF66,FF9933,FF3300,CCCCFF,"
       + "CC66CC,CC0099,99CC66,996633,990000,6699FF,6633CC,33FF99,339966,00FF00,"
       + "0066FF,FFFF33,FF9900,FF00FF,CCCCCC,CC6699,CC0066,99CC33,996600,66FFFF,"
       + "6699CC,663399,33FF66,339933,00CCFF,0066CC,FFFF00,FF66FF,FF00CC,CCCC99,"
       + "CC6666,CC0033,99CC00,9933FF,66FFCC,669999,663366,33FF33,339900,3300FF,"
       + "00CCCC,006699,FFCCFF,FF66CC,FF0099,CCCC66,CC6633,CC0000,9999FF,9933CC,"
       + "66FF99,669966,663333,33FF00,3366FF,00CC99,006666,FFCCCC,FF6699,FF0066,"
       + "CCCC33,CC6600,99FFFF,9999CC,993399,66FF66,669933,663300,33CCFF,3366CC,"
       + "00CC66,006633,FFCC99,FF6666,FF0033,CCCC00,CC33FF,99FFCC,999999,993366,"
       + "66FF33,669900,6600FF,33CCCC,336699,00CC33,006600,FFCC66,FF6633,CC99FF,"
       + "CC33CC,99FF99,999966,993333,66FF00,6666FF,6600CC,33CC99,336666,00CC00,"
       + "0033FF,FFCC33,FF6600,CCFFFF,CC99CC,CC3399,99FF66,999933,993300,66CCFF,"
       + "6666CC,660099,33CC66,336633,0099FF,0033CC,FFCC00,FF33FF,CCFFCC,CC9999,"
       + "CC3366,99FF33,999900,9900FF,66CCCC,666699,660066,33CC33,336600,00FFFF,"
       + "0099CC,003399,FF99FF,FF33CC,CCFF99,CC9966,CC3333,99FF00,9966FF";

        

        public PreDefinedColors()
        {
            GeneratePredefinedColors(colorDefinitions.Split(','));
        }

        #region ICustomColor
        private List<Color> _colorList = new List<Color>();
        public List<Color> colorList
        {
            get { return _colorList; }
            set
            {
                if (_colorList != value)
                {
                    _colorList = value;
                }
            }
        }


        public Color GetColorFromIndex(int index, double alpha)
        {
            if (index < 0)
            {
                index = 0;
            }
            else if (index >= colorList.Count)
            {
                // wrap around to a valid color
                index = (colorList.Count -1) % index;
            }

            return colorList[index];
        }
        #endregion ICustomColor


        private void GeneratePredefinedColors(string[] preDefinedColorStringArray)
        {
            foreach (var c in preDefinedColorStringArray)
            {
                colorList.Add(RGB.GetColorFromHex(.6, c.Substring(0, 2) + c.Substring(2, 2) + c.Substring(4, 2)));
            }
        }

    }
}
